<?php $header=$this->action('ZfcAdmin\Controller\AdminController', 'headerAction');
	  $baseUrl = $header->headerarray['baseUrl'];
?>
<?php if(isset($_SESSION['admin'])){?>
<html>
	<body>		
		<?php if(isset($_GET['area_id']) && $_GET['area_id']!=""){?>
		<h3>Edit Area:</h3>
		<?}else{?>
		<h3>Add Area:</h3>
		<?}?>
		<center>
			<form id="area_form" name="area_form" method="post" action="">
					<div>
						<?php if(isset($_GET['area_id']) && $_GET['area_id']!=""){?>
							Districts: <input type="text" id="dist_name" name="dist_name" value="<? echo $this->areas_details->dist_name;?>" readonly="readonly">
							<input type="hidden" id="districts" name="districts" value="<? echo $this->areas_details->district_id;?>"><br/><br/>
							Area: <input type="text" id="area" name="area" value="<? echo $this->areas_details->area_name;?>">
							<input type="hidden" id="area_id" name="area_id" value="<? echo $this->areas_details->area_id;?>">
						<?}else{?>
							Districts :<select id="districts" name="districts">
								<option value="">Select a district</option>
							<? if(count($this->list_districts)>0){ foreach($this->list_districts as $district){
							   if(isset($_GET['dist_id']) && $_GET['dist_id']!=""){ if($_GET['dist_id']==$district->district_id){?>
								<option value="<? echo $district->district_id;?>" selected="selected"><? echo $district->district_name;?></option>
								<?}else{?>
								<option value="<? echo $district->district_id;?>"><? echo $district->district_name;?></option>
								<?}}else{?>
									<option value="<? echo $district->district_id;?>"><? echo $district->district_name;?></option>
								<?}?>
							<?}}else{?>
								<option value="">No districts</option>
							<?}?>
							</select><br/>	<br/><br/>				
							Area:
							<div id="subdiv">			
								<div id ="txtdiv0">
									<input type="text" id="area" name="area[]">&nbsp;&nbsp;
									<input type="button" onclick="addTextBox()" id="add0" value="+">
									<input type="button" onclick="removeTextBox()" id="remove0" style="display:none;" value="-"><br/>
								</div>	
							</div>
						<?}?>
					</div>
				<br/><br/>				
					<a href="<? echo $baseUrl.'admin/area-lists'?>">Back</a>&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="btn_area" name="btn_area" value="Save" onclick="return add_area()">
			</form>
		</center>
	</body>
</html>
<script>
var i=0;
function addTextBox(){
	i++;
	$('#subdiv').append('<div id = "txtdiv'+i+'"><input type="text" id="area'+i+'"  name="area[]">&nbsp;&nbsp;<input type="button" onclick="addTextBox()" id="add'+i+'" value="+"><input type="button" onclick="removeTextBox()" id="remove'+i+'" value="-"></div>');
	var j = i - 1;
	$('#remove'+j).show();
	$('#remove'+i).hide();
	$('#add'+j).hide();
	
}
function removeTextBox(){
	$('#txtdiv'+i).remove();
	i--;
	$('#remove'+i).hide();
	$('#add'+i).show();
}
</script>
<? } else {?>
<script>
	window.location=ADMIN_BASE_URL+'admin';
</script>
<?}?>